home *** CD-ROM | disk | FTP | other *** search
- | auto-detaching baserelative startup code for gcc v2.3.3
- | (c) by M.Fleischer and G.Nikl Fri May 27 20:33 1994
- | No real bugs known
-
- | some specific defines
-
- _LVOForbid = -132
- _LVOPermit = -138
- _LVOAllocMem = -198
- _LVOFreeMem = -210
- _LVOAddTail = -246
- _LVOFindTask = -294
- _LVOGetMsg = -372
- _LVOReplyMsg = -378
- _LVOWaitPort = -384
- _LVOCloseLibrary = -414
- _LVOOpenLibrary = -552
-
- _LVOLock = -84
- _LVOUnlock = -90
- _LVOCurrentDir = -126
- _LVOCreateProc = -138
-
- tc_MemEntry = 74
- pr_MsgPort = 92
- pr_CLI = 172
-
- cli_Module = 60
-
- SHARED_LOCK = -2
-
- RETURN_OK = 0
- RETURN_FAIL = 20
-
- | public symbols
-
- .globl ___subexit
- .globl _geta4
-
- .text
-
- | first entry - init some vars, check for cli or wb start
-
- start: movel a0,d3
-
- jbsr _geta4
-
- lea a4@(__edata:W),a0
- lea a4@(__end:W),a1
- jra clrbss2
- clrbss1: clrl a0@+
- clrbss2: cmpl a1,a0
- bcss clrbss1
-
- movel sp,a4@(_SaveSP:W)
- movel 4:W,a6
- movel a6,a4@(_SysBase:W)
-
- subal a1,a1
- jsr a6@(_LVOFindTask:W)
- movel d0,a3
-
- movel a4@(_cmdLine:W),d0
- exg d0,d3
- bnes fromCLI
-
- tstl a3@(pr_CLI:W)
- exg d0,d3
- bne Detach
-
- | wb start - get wbmsg
-
- fromWB: lea a3@(pr_MsgPort:W),a0
- jsr a6@(_LVOWaitPort:W)
- lea a3@(pr_MsgPort:W),a0
- jsr a6@(_LVOGetMsg:W)
- movel d0,a4@(__WBenchMsg:W)
-
- | common - open all libs
-
- fromCLI: tstl _cmdLine
- beqs skip1
-
- moveq #RETURN_FAIL,d7
- lea a4@(___dosname:W),a1
- moveq #33,d0
- jsr a6@(_LVOOpenLibrary:W)
- movel d0,a4@(_DOSBase:W)
- beq nolib
- movel d0,a6
- lea a4@(_curDir:W),a2
- movel a2@,d1
- jsr a6@(_LVOCurrentDir:W)
- movel d0,a2@
-
- | call __submain()
-
- skip1: movel d3,a4@(___commandline:W)
- jmp ___submain
-
- | __subexit() entry - get return val, restore stackptr
-
- ___subexit: movel sp@(4:W),d0
- movel a4@(_SaveSP:W),sp
-
- | cleanup - close lib, reply wbmsg
-
- movel a4@(_SysBase:W),a6
- tstl a4@(_cmdLine:W)
- beqs nolib
-
- movel a6,a5
- movel a4@(_DOSBase:W),a6
- movel a4@(_curDir:W),d1
- jsr a6@(_LVOCurrentDir:W)
- movel d0,d1
- jsr a6@(_LVOUnlock:W)
- movel a6,a1
- movel a5,a6
- jsr a6@(_LVOCloseLibrary:W)
-
- nolib: movel a4@(__WBenchMsg:W),d2
- beqs todos
- jsr a6@(_LVOForbid:W)
- movel d2,a1
- jsr a6@(_LVOReplyMsg:W)
-
- todos: movel d7,d0
- rts
-
- | get baseptr
-
- _geta4: lea ___a4_init,a4
- rts
-
- | detach the process from the shell task
-
- Detach: lea a4@(___dosname:W),a1
- moveq #33,d0
- jsr a6@(_LVOOpenLibrary:W)
-
- | need a private DOSBase !!!
-
- movel d0,d6
- beq nodos
-
- movel a3@(pr_CLI:W),a3
- addal a3,a3
- addal a3,a3
- lea a3@(cli_Module:W),a3
-
- | length of the commandline
-
- movel d3,a0
- moveq #7,d0
- arglen: addql #1,d0
- cmpb #10,a0@+
- bnes arglen
- moveq #-8,d2
- andl d0,d2
-
- | number of hunks
-
- moveq #24,d5
- movel a3@,a0
- cntsegs: addal a0,a0
- addal a0,a0
- addql #8,d5
- movel a0@,d0
- movel d0,a0
- bnes cntsegs
- addl d2,d5
-
- | needed memory for memlist and commandline
-
- movel d5,d0
- moveq #1,d1
- swap d1
- jsr a6@(_LVOAllocMem:W)
- movel d0,a2
- movel a2,d0
- beq nomem
-
- | setup our memlist - first hunks, then cmdLine
-
- lea a2@(16:W),a1
- movel a3@,a0
- addsegs: addal a0,a0
- addal a0,a0
- movel a0@-,d0
- movel a0,a1@+
- movel d0,a1@+
- addqw #1,a2@(14:W)
- movel a0@(4:W),d0
- movel d0,a0
- bnes addsegs
-
- lea a1@(8:W),a0
- movel a0,a1@+
- movel d2,a1@+
- addqw #1,a2@(14:W)
-
- | new commandline for later use
-
- movel a1,a4@(_cmdLine:W)
- movel d3,a0
- cpyarg: moveb a0@+,a1@
- cmpb #10,a1@+
- bnes cpyarg
-
- | new currentdir lock for background process
-
- clrl sp@-
- movel sp,d1
- moveq #SHARED_LOCK,d2
- exg d6,a6
- jsr a6@(_LVOLock:W)
- exg d6,a6
- movel d0,a4@(_curDir:W)
- addqw #4,sp
-
- | create process with disabled multitasking !!!
-
- jsr a6@(_LVOForbid:W)
-
- movel a4@(__procname:W),d1
- movel a4@(__priority:W),d2
- movel a3@,d3
- movel a4@(__stack:W),d4
- exg d6,a6
- jsr a6@(_LVOCreateProc:W)
- exg d6,a6
- movel d0,a5
- movel a5,d0
- beqs noproc
-
- | insert memlist to free all memory at process end
-
- lea a5@(-pr_MsgPort+tc_MemEntry:W),a0
- movel a2,a1
- jsr a6@(_LVOAddTail:W)
-
- | clear cli_Module to prevent unloading by the shell
-
- clrl a3@
-
- | reenable multitasking - all done or maybe not ...
-
- noproc: jsr a6@(_LVOPermit:W)
-
- | if (a5 != 0) goto skip;
-
- movel a5,d0
- bnes nomem
-
- | error creating the process - free lock and memory
-
- movel a4@(_curDir:W),d1
- exg d6,a6
- jsr a6@(_LVOUnlock:W)
- exg d6,a6
-
- movel a2,a1
- movel d5,d0
- jsr a6@(_LVOFreeMem:W)
-
- | close dos.library
-
- nomem: movel d6,a1
- jsr a6@(_LVOCloseLibrary:W)
-
- | exit graceful
-
- nodos: moveq #RETURN_OK,d0
- rts
-
- | data area
-
- .data
-
- .lcomm _SaveSP,4
- .lcomm _curDir,4
- .lcomm _cmdLine,4
- .lcomm _DOSBase,4
- .comm _SysBase,4
- .comm __WBenchMsg,4
- .comm ___commandline,4
-